﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;


namespace automobili_data
{
    abstract class AutomobiliDataFactory
    {
        private static String connectionString;

        protected static String ConnectionString
        {
            get { return AutomobiliDataFactory.connectionString; }
            set { AutomobiliDataFactory.connectionString = value; }
        }

        protected static DatabaseKind databaseKind;


        /// <summary>
        /// Initializes database factory class.
        /// </summary>
        /// <param name="connString"></param>
        /// <param name="dbKind"></param>
        public static void init(String connString, DatabaseKind dbKind)
        {
            connectionString = connString;
            databaseKind = dbKind;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        static AutomobiliDataFactory createFactory()
        {
            if (databaseKind == DatabaseKind.MySql)
            {
                return new MysqlAutomobiliDataFactory();
            }
            else
            {
                throw new Exception("Unsupported database type");
            }
            
        }

        /// <summary>
        /// 
        /// </summary>
        public static AutomobiliDataFactory instance = createFactory();

        /// <summary>
        /// 
        /// </summary>
        protected AutomobiliDataFactory() { }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public abstract IDbConnection createConnection();

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public abstract AutomobiliDataManagerImpl createDBAdapter();

    }
}
